<?php
$code= $_GET['code'];
$state= $_GET['state'];
$realUrl=$_GET['url'];
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx8ad440a19b0a4556&secret=a85a374841318ee15237e647f6548dff&code=".$code."&grant_type=authorization_code";
$rtn = json_decode(http_request($url),TRUE);
//var_dump($rtn);
$realUrl=$realUrl.'?openid='.$rtn['openid'];
header('location: '.$realUrl);



function http_request($url,$data = null)
    {
    	$curl = curl_init();
		  curl_setopt($curl, CURLOPT_URL, $url);
		  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    	if (!empty($data)) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
      }
    	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    	$output = curl_exec($curl);
		  curl_close($curl);
      return $output;
    }
?>
